package everyday;

import java.util.HashMap;
import java.util.Map;

public class T2404 {
    public int mostFrequentEven(int[] nums) {
        int n=nums.length;
        Map<Integer,Integer> map=new HashMap<>();
        for (int num : nums) {
            if (num % 2 == 0) {
                if (map.containsKey(num)) {
                    map.put(num, map.get(num) + 1);
                } else {
                    map.put(num, 1);
                }
            }
        }
        if (map.size()==0)return -1;
        int res=0;
        int minNum=0;
        for(int key:map.keySet()){
            int sum=map.get(key);
            if (sum>res){
                res=sum;
                minNum=key;
            }else if(sum==res){
                minNum=Math.min(minNum,key);
            }
        }
        return minNum;
    }
}
